package cn.anecansaitin.whimsy.common.extension.comboSystem.skills.rockSceptre;

import cn.anecansaitin.whimsy.common.entity.WeaponSwingCollision;
import cn.anecansaitin.whimsy.common.extension.comboSystem.ExtraData;
import cn.anecansaitin.whimsy.common.extension.comboSystem.INormalSkill;
import cn.anecansaitin.whimsy.common.item.RockSceptre;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import software.bernie.geckolib.animatable.GeoItem;

public class Attack3 implements INormalSkill {
    @Override
    public int precastTick() {
        return 8;
    }

    @Override
    public int activeTick() {
        return 1;
    }

    @Override
    public int backswingTick() {
        return 10;
    }

    @Override
    public void prePrecast(Player player, ExtraData extra) {
        if (!player.level().isClientSide) {
            extra.getData("itemStack", ItemStack.class).ifPresent((i) -> {
                RockSceptre item = (RockSceptre) i.getItem();
                item.triggerAnim(player, GeoItem.getOrAssignId(i, (ServerLevel) player.level()), "con", "attack3.precast");
                item.triggerAnim(player, GeoItem.getOrAssignId(i, (ServerLevel) player.level()), "stone", "attack");
            });
        }
    }

    @Override
    public void precast(int skillTick, Player player, ExtraData extra) {

    }

    @Override
    public void preActive(Player player, ExtraData extra) {
        if (!player.level().isClientSide) {
            extra.getData("itemStack", ItemStack.class).ifPresent((i) -> {
                RockSceptre item = (RockSceptre) i.getItem();
                item.triggerAnim(player, GeoItem.getOrAssignId(i, (ServerLevel) player.level()), "con", "attack3.active");
            });

            player.level().playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_SWEEP, player.getSoundSource(), 1.0F, 1.0F);
        }
    }

    @Override
    public void active(int skillTick, Player player, ExtraData extra) {
        WeaponSwingCollision.sectorRange(player, 4, 2f, 1, 12f);
    }

    @Override
    public void preBackswing(Player player, ExtraData extra) {

    }

    @Override
    public void backswing(int skillTick, Player player, ExtraData extra) {

    }

    @Override
    public void finish(Player player, ExtraData extra) {
        if (!player.level().isClientSide) {
            extra.getData("itemStack", ItemStack.class).ifPresent((i) -> {
                RockSceptre item = (RockSceptre) i.getItem();
                item.triggerAnim(player, GeoItem.getOrAssignId(i, (ServerLevel) player.level()), "con", "idle");
                item.triggerAnim(player, GeoItem.getOrAssignId(i, (ServerLevel) player.level()), "stone", "idle");
            });
        }
    }

    @Override
    public boolean canCachingKey(int skillTick, ExtraData extra) {
        return skillTick >= 8 && skillTick <= 19;
    }

    @Override
    public boolean canDeriving(int skillTick, ExtraData extra) {
        return skillTick >= 9 && skillTick <= 19;
    }

    @Override
    public String getName() {
        return "attack3";
    }
}
